import java.util.*;

public class MC0203小码哥的艰难选择 {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        // code here
        int n = input.nextInt();
        HashMap<String, Integer> map = new HashMap<>();
        HashMap<String, Integer> timeMap = new HashMap<>();
        for (int i = 0; i < n; i++) {
            String name = input.next();
            int scoreChange = input.nextInt();
            map.put(name, map.getOrDefault(name, 1000) + scoreChange);
            timeMap.put(name, i);
        }
        //排序
        ArrayList<String> flowerNames = new ArrayList<>(map.keySet());
        flowerNames.sort((name1, name2) -> {
            int score1 = map.get(name1);
            int score2 = map.get(name2);
            if (score1 != score2) {
                // 规则1：比较分数。分数不同时，分数低的排前面
                return Integer.compare(score1, score2);
            } else {
                Integer time1 = timeMap.get(name1);
                Integer time2 = timeMap.get(name2);
                return Integer.compare(time1, time2);
            }
        });
        String loserName = flowerNames.get(0);
        int loserScore = map.get(loserName);
        System.out.println(loserName + "\n" + loserScore);
        input.close();
    }
}
